package com.wc.AlgoOJ.SQ1307;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/14 11:39
 * @description 数列分段2
 * http://43.138.190.70:8888/p/SQ1307
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int n, m;
    static int maxN = (int) 1e5 + 7;
    static long maxNum = Long.MAX_VALUE;
    static int[] nums = new int[maxN];

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            nums[i] = sc.nextInt();
        }
        out.println(ds());
        out.flush();
    }

    static long ds() {
        long l = 1;
        long r = maxNum;
        while (l <= r) {
            long mid = l + (r - l) / 2;
            if (check(mid)) {
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        return l;
    }


    static boolean check(long minSub) {
        int group = 1;
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            if (nums[i] > minSub) {
                return true;
            }

            sum += nums[i];
            if (sum > minSub) {
                sum = nums[i];
                group++;
            }
        }
        return group > m;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }
}
